<template>
  <div id="app" class="app-wrapper" @mouseover="cmouseovered">
    <!-- <router-view /> -->
    <router-view v-if="routerAlive"></router-view>
  </div>
</template>

<script>
import Cookies from 'js-cookie'
export default {
  name: 'App',
  provide() {
      return {
          reload: this.reload,
      }
  },
  data() {
    return {
      timeOut: 5 * 60 * 1000, // 5 minutes,
      // reload: this.reload,
      routerAlive: true 
    };
  },

  mounted() { 
    this.countTime()
    window.addEventListener('keydown', this.cmouseovered);
  },
  methods: {
    reload() {
      this.routerAlive = false
      this.$nextTick(function () {
          this.routerAlive = true
      })
    },
    countTime() {
      let timeout = Cookies.get('UILogoutInterval') || this.timeOut
      timeout = timeout === 0 ? 1000000000000000 : timeout
      const vm = this
      this.timer = setTimeout(function() {
        vm.logout()
      }, timeout)
    },
    cmouseovered() {
      clearTimeout(this.timer)
      this.countTime()
    },
    async logout() {
      await this.$store.dispatch('user/logout')
      this.$router.push(`/login`)
      clearInterval(this.tiemer)
      window.removeEventListener('keydown', this.clearTimer);
    },
  },
}
</script>
